package com.ruoyi.web.controller.app.user;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.RestaurantCustomer;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.resp.DeviceInfoDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: ruohao
 * @Date: 2023/8/23
 **/
@RestController
@RequestMapping("/app/account")
public class AppAcountController extends BaseController {
    @Resource
    private SysUserMapper sysUserMapper;

    @PostMapping("/login")
    public AjaxResult login(@Validated @RequestBody RestaurantCustomer customer) {
        return success();
    }

    @PostMapping("/refreshToken")
    public AjaxResult refreshToken(@Validated @RequestBody RestaurantCustomer customer) {
        return success();
    }

    @Log(title = "上报设备号", businessType = BusinessType.UPDATE)
    @PostMapping("/reportDeviceInfo")
    public AjaxResult reportDeviceInfo(@Validated @RequestBody DeviceInfoDTO deviceInfoDTO) {
        logger.info("上报设备号 {} {}", deviceInfoDTO.getRegisterId(), SecurityUtils.getUserId());
        SysUser sysUserUpdate = new SysUser();
        sysUserUpdate.setUserId(SecurityUtils.getUserId());
        sysUserUpdate.setRegisterId(deviceInfoDTO.getRegisterId());
        sysUserMapper.updateUser(sysUserUpdate);
        return success();
    }
}
